package leetcode_201_300;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

public class LeeCode_299 {
    public static void main(String[] args) {
        System.out.println(getHint("1122", "1222"));
    }
    private static String getHint(String secret, String guess) {
        int len = secret.length();
        int a = 0, b = 0;
        int[] cs = new int[10];
        int[] cg = new int[10];
        for (int i = 0; i < len; i++) {
            if (secret.charAt(i) == guess.charAt(i)){
                a++;
            }else {
                cs[secret.charAt(i) - '0']++;
                cg[guess.charAt(i) - '0']++;
            }
        }
        for (int i = 0; i < 10; i++) {
            b += Math.min(cs[i], cg[i]);
        }
        return a + "A" + b + "B";
    }
}
